# -*- coding: UTF-8 -*-
# cython: language_level=3
import os
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from db.oracle_db import OracleDB


def screen_shot():
    os.system('taskkill /im chromedriver.exe /F')
    time.sleep(10)
    os.system('taskkill /im chrome.exe /F')

    oracleDB = OracleDB()

    # 创建一个参数对象，用来控制chrome以无界面的方式打开
    options = Options()
    options.add_argument('--headless')
    # 初始化一个谷歌浏览器实例
    browser = webdriver.Chrome(options=options)

    # resize
    browser.set_window_size(1920, 1080)
    print("-----start-----")
    sql = f'''SELECT * FROM TAB_VIDEO_SITE_INFO WHERE SITE_TYPE=3 AND MONITOR_STATUS = 0 and id < 10000000'''
    for item in oracleDB.find(sql):
        vid = item[0]
        url = item[3]
        try:
            print(vid)
            browser.get(url)
            browser.save_screenshot(f"Z:\\zk_spider2\\wuzheng_screenshot\\{vid}.png")
            sql = f'''update  TAB_VIDEO_SITE_INFO set PAGE_IMAGE_URL = '{vid}.png' where ID = {vid}'''
            print(oracleDB.update(sql))
        except:
            pass
    browser.quit()
    print("-----end-----")


if __name__ == '__main__':
    screen_shot()
